const App = getApp()
Page({
  data: {
    page: 1,
    nomore: false,
    list: [],
    pageShow:false
  },
  onLoad: function (options) {

  },
  onReady: function () {

  },
  onShow: function () {
    let that = this
    that.setData({
      page: 1,
      list: []
    })
    that.list()
  },

  async list() {
    let that = this
    await App.api.$http({
      url: 'Oilorder/lists',
      method: 'GET',
      data: {
        page: that.data.page,
        datatype: ''
      }
    }, {}).then(res => {
      that.setData({
        pageShow:true
      })
      wx.hideNavigationBarLoading()
      wx.hideLoading()
      wx.stopPullDownRefresh();
      if (that.data.page == 1) {
        that.setData({
          list: []
        })
      }
      if (res) {
        if (that.data.page < res.data.list.last_page) {
          let hotPage = that.data.page + 1;
          that.setData({
            page: hotPage,
            nomore: true
          })
        } else {
          that.setData({
            nomore: false
          })
        }
        let lists = that.data.list.concat(res.data.list.data)
        that.setData({
          list: lists
        })
      }
    })
  },

  // 详情
  detail(e) {
    let id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/car/orderdetail/orderdetail?type=' + 'user' + '&&id=' + id,
    })
  },
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showNavigationBarLoading();
    wx.showLoading({
      title: '刷新中...',
    })
    this.setData({
      page:1
    })
    this.list()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.nomore) {
      this.list();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})